package com.cyzy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyzy.domain.TWallet;
import com.cyzy.dto.ResponseData;
import com.cyzy.service.TWalletService;
import com.cyzy.mapper.TWalletMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 10204
 * @description 针对表【t_wallet(钱包表，用于存储用户的余额和支付密码等信息)】的数据库操作Service实现
 * @createDate 2024-11-22 16:42:15
 */
@Service
public class TWalletServiceImpl extends ServiceImpl<TWalletMapper, TWallet> implements TWalletService {

    @Autowired
    private TWalletMapper tWalletMapper;

    @Override
    public ResponseData getTWallet(String userId) {
        //我是大帅哥
        QueryWrapper<TWallet> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        TWallet tWallet = tWalletMapper.selectOne(queryWrapper);
        if (tWallet == null) {
            TWallet tWallet1 = new TWallet();
            tWallet1.setPayPassword("123456");
            tWallet1.setBalance("0.00");
            tWallet1.setMoneyType("CNY");
            tWallet1.setUserId(userId);
            int re = tWalletMapper.insert(tWallet1);
            if (re == 0) {
                return ResponseData.no();

            } else {
                return new ResponseData(200, "success", tWallet, 0);
            }
        } else {
            return new ResponseData(200, "success", tWallet, 0);
        }
    }
}





